package LeetCode;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}22:12
 */
public class LeetCode283 {
    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        new LeetCode283().moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }
//    public void moveZeroes(int[] nums) {
//        int[] arr = new int[nums.length];
//        int index = 0;
//        for (int num : nums) {
//            if (num != 0){
//                arr[index++] = num;
//            }
//        }
//        nums = arr;
//    }
    public void moveZeroes(int[] nums){
        int j = 0;
        for (int i = 0; i < nums.length; i++){
            if (nums[i] != 0){
                nums[j] = nums[i];
                j++;
            }
            if (i != j){
                nums[i] = 0;
            }
        }
    }
}
